package wwl.lsf.imitateMybatis;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

//@Component
public class MyFactoryBean implements FactoryBean, InvocationHandler {

   Class clz;

  public MyFactoryBean(Class clz) {
    this.clz = clz;
  }

  @Override
  public Object getObject() throws Exception {
    Class[] ccc = new Class[]{this.clz};
    Object o = Proxy.newProxyInstance(this.getClass().getClassLoader(), ccc, this);
    return o;
  }

  @Override
  public Class<?> getObjectType() {
    return this.clz;
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Select annotation = method.getAnnotation(Select.class);
    System.out.println(annotation.value()[0]);
    return null;
  }
}
